package cn.cs.service.impl;

import cn.cs.client.AdBannerClient;
import cn.cs.common.*;
import cn.cs.pojo.AdBanner;
import cn.cs.pojo.RepairUser;
import cn.cs.service.AdBannerService;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service
public class AdBannerServiceImpl implements AdBannerService {

    @Resource
    private AdBannerClient adBannerClient;

    public AdBanner getAdbannerById(String id)throws Exception{
        return adBannerClient.getAdbannerById(id);
    }

    public List<AdBanner> getAdbannerListByMap(Map<String,Object> param)throws Exception{
        return adBannerClient.getAdbannerListByMap(param);
    }

    public Integer getAdbannerCountByMap(Map<String,Object> param)throws Exception{
        return adBannerClient.getAdbannerCountByMap(param);
    }

    public Integer addAdbanner(AdBanner adbanner)throws Exception{
        return adBannerClient.addAdbanner(adbanner);
    }

    public Integer modifyAdbanner(AdBanner adbanner)throws Exception{
        return adBannerClient.modifyAdbanner(adbanner);
    }

    public Integer deleteAdbannerById(String id)throws Exception{
        return adBannerClient.deleteAdbannerById(id);
    }

    public Page<AdBanner> queryAdbannerPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize)throws Exception{
        Integer total = adBannerClient.getAdbannerCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<AdBanner> adbannerList = adBannerClient.getAdbannerListByMap(param);
        page.setRows(adbannerList);
        return page;
    }

    @Override
    public Dto getAllAdBanners(HttpServletRequest request) {
            String type= request.getParameter("type");
            if(EmptyUtils.isEmpty(type)){
                type = "2";
            }
            List<AdBanner> list = adBannerClient.getAllAdBanners(type);
            if(!EmptyUtils.isEmpty(list)){
                return DtoUtil.returnDataSuccess(list);
            }else{
                return  DtoUtil.returnFail("没有banner","0002");
            }
    }
}
